/**
 * ClassificationDAO.java
 *
 * Enterprise Java
 *
 * Author:  Matthew Braddy
 * Created: Nov 22, 2010
 *
 */

package java113.labs;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
import java113.dataAccess.DAOBase;
import java113.dataAccess.DataManager;

/**
 *
 * @author Matthew Braddy
 */
public class ClassificationDAO extends DAOBase {

    private Properties properties;

    private DataManager m_oDataManager;

    private Classification classification;

    public ClassificationDAO(Properties properties, DataManager m_oDataManager) throws Exception {

        this.properties = properties;

        this.m_oDataManager = m_oDataManager;

        String sqlFileName = this.properties.getProperty("path.sql") +
                             this.properties.getProperty("sql.file.classification");

        this.load(sqlFileName, this.properties.getProperty("webApp"));

    }

    public Classification getClassification(int inId) throws SQLException {

        String strSQL;
        ResultSet resultSet = null;
        Statement statement = null;

        try
        {
            strSQL = this.getSQL ("get classification");  //obtain the SQL by name that is loaded in memory

            strSQL = strSQL.replace ("%%ID%%", String.valueOf (inId));

            statement = (Statement) this.m_oDataManager.createStatement ();  //create a statement for our pending transaction
            resultSet = this.m_oDataManager.executeQuery ((java.sql.Statement) statement,strSQL);  //execute the query

            if(resultSet != null)  //defensive coding
            {

                while (resultSet.next()) {

                    classification = new Classification();

                    int    id                = resultSet.getInt("id");
                    String classificationStr = resultSet.getString("type");
                    
                    classification.setId(id);
                    classification.setType(classificationStr);

                }

            }

            this.m_oDataManager.close ((java.sql.Statement) statement);
        }
        catch(Exception Ex)
        {
            Ex.printStackTrace ();
        }

        return classification;

    }

}
